<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>借货订单相关的出库单记录</title>
    <script type="text/javascript">
      var deliveryId;
      Ext.onReady(function(){
        var  deliveryForLoanDS = Ext.create('Ext.data.Store', {
          //autoDestroy : true,
          model : 'LoanOrderModel',
          proxy : {
            type : 'ajax',
            extraParams:{id:'<%=params[:id]%>'},
            url : '/loan_delivery/getLoanDeliverysByLoanId',
            reader : {
              type : 'json',
              root : 'root',
              totalProperty : 'totalProperty'// 数据集记录总数
            }
          },
          pageSize : pageSize,
          autoLoad : true
        });

        //生成要订单的产品的Grid
        var deliveryForLoanGrid = Ext.create('Ext.grid.Panel', {
          title:'借货出库单列表',
          store: deliveryForLoanDS,
          columns : [Ext.create('Ext.grid.RowNumberer'),{
              header: 'DB',
              dataIndex: 'id',
              width: 50
            },{
              header: '借货订单单号',
              dataIndex: 'loan_number',
              width: 130
            },{
              header: '出库单号',
              dataIndex: 'order_number',
              width: 130
            },{
              header: '客户',
              dataIndex: 'customer_name',
              width: 160
            },{
              header: '调出仓库',dataIndex: 'warehouse_name',width: 100
            },{
              header: '出库日期',
              dataIndex: 'action_date',
              renderer: Ext.util.Format.dateRenderer('Y-m-d'),
              width: 80
            },{
              header: '操作员',
              dataIndex: 'employee_name',
              width: 60
            },{
              header: '部门',
              dataIndex: 'department_name',
              width: 70
            },{
              header: '审批状态',
              dataIndex: 'auditing_status',
              renderer: auditingStatusRender,
              width: 60
            },{
              header: '订单状态',
              dataIndex: 'deal_with_status',
              renderer: dealWithStatusRender,
              width: 60
            },{
              header: '生成日期',
              dataIndex: 'created_at',
              renderer: Ext.util.Format.dateRenderer('Y-m-d H:i'),width: 115
            },{
              header: '修改日期',
              dataIndex: 'updated_at',
              renderer: Ext.util.Format.dateRenderer('Y-m-d H:i'),width: 115
            }],
          selModel : Ext.create('Ext.selection.CheckboxModel'),
          loadMask: true,
          width: 980,
          height: 270,
          frame: true
        });


        deliveryForLoanGrid.on('itemdblclick', function(gridPanel, record,item,index,e,options){
          deliveryId = deliveryForLoanDS.getAt(index).get('id');
          var saleOrderNumber = deliveryForLoanDS.getAt(index).get('order_number');
          //deliveryForLoanDS.load();
            loanDeliveryDetailDS.removeAll();
            loanDeliveryDetailDS.load({params:{'loan_delivery_id': deliveryId}});
          deliveryOrderDetailGrid.setTitle("出库单："+saleOrderNumber+"，的详细信息");
        });

        //--------------------------出库单详细，双击后可显示数据----------------
        var loanDeliveryDetailDS = Ext.create('Ext.data.Store', {
          //autoDestroy : true,
          model : 'LoanDeliveryDetailModel',
          proxy : {
            type : 'ajax',
            url : '/loan_delivery/getLoanDeliveryDetailsById',
            reader : {
              type : 'json',
              root : 'root',
              totalProperty : 'totalProperty'// 数据集记录总数
            }
          }
        });
        
        //生成要订单的产品的Grid
        var deliveryOrderDetailGrid = Ext.create('Ext.grid.Panel', {
          title:'出库单详细列表',
          store: loanDeliveryDetailDS,
          columns : [Ext.create('Ext.grid.RowNumberer'),{
              header: 'DB',
              dataIndex: 'id',
              width: 50
            },{
              header: '产品名称',
              dataIndex: 'product_name',
              width: 230
            },{
              header: '编号',dataIndex: 'product_number',width: 100
            },{
              header: '规格',
              dataIndex: 'product_spec',
              width: 80
            },{
              header: '数量',
              dataIndex: 'quantity',
              align: 'right',
              width: 80
            },{
              header: '套装或单品',
              dataIndex: 'is_suit',
              width: 70
            },{
              header: '备注',
              dataIndex: 'description',
              width: 270
            }],
          loadMask: true,
          width: 980,
          height: 295,
          frame: true
          //title: '进货品种列表',
          //plain:true,
          //plugins: checkColumn,
        });
        //总的panel
        var workbenchPanel = Ext.create('Ext.form.Panel', {
          width: 990,
          height: 590,
          frame:false,          
          layout: {type: 'table',columns:1},          
          items:[deliveryForLoanGrid,deliveryOrderDetailGrid]
        });
        workbenchPanel.render("delivery_for_loan_workbench_panel");
      })
    </script>
  </head>
  <body>
    <div id="delivery_for_loan_workbench_panel"></div>
  </body>
</html>